package com.lovo.stock.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.stock.bean.count.SaleMonthBean;
import com.lovo.stock.bean.count.SaleTypeBean;
import com.lovo.stock.mapper.SaleCountMapper;
import com.lovo.stock.service.ISaleCountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SaleCountServiceImpl extends ServiceImpl<SaleCountMapper, SaleTypeBean> implements ISaleCountService {
    @Autowired
    SaleCountMapper saleCountMapper;

    @Override
    public List<SaleTypeBean> queryTypeSaleCount(String startTime, String endTime) {
        return saleCountMapper.selectTypeSaleCount(startTime, endTime);
    }

    @Override
    public List<SaleTypeBean> queryProductSaleCount(String startTime, String endTime) {
        return saleCountMapper.selectProductSaleCount(startTime,endTime);
    }

    @Override
    public Map<Integer,List<SaleMonthBean>> queryTypeSaleCountByMonth(String time) {
        Map<Integer,List<SaleMonthBean>> listMap=new HashMap<>();
        for (int i = 0; i < 13; i++) {
            listMap.put(i,new ArrayList<>());
        }
        List<SaleTypeBean> list=saleCountMapper.selectTypeSaleCountByMonth(time);
        for (SaleTypeBean s:list
             ) {
            SaleMonthBean saleMonthBean=new SaleMonthBean();
            saleMonthBean.setName(s.getType());
            saleMonthBean.setSumPrice(s.getSumPrice());
            List<SaleMonthBean> saleMonthBeans=listMap.get(Integer.parseInt(s.getMonth()));
            saleMonthBeans.add(saleMonthBean);
            listMap.put(Integer.parseInt(s.getMonth()),saleMonthBeans);
        }
        return listMap;
    }
}
